<template>
  <div>
    <Row>
      <i-col span="12">
        <Card class="my-card">
          <p slot="title">
              <Icon type="md-color-palette"></Icon>
              生成Vue前台代码
          </p>
          <Spin size="large" fix v-show="spinShow"></Spin>
          <Form  :label-width="80" ref="sform" v-show="formShow" inline>
            <Row :gutter="32">
              <Col span="12">
                <FormItem label="数据表" required class="my-form-item">
                  <Select placeholder="请选择数据表" v-model="table" @on-change="handleTableSelect">
                    <Option v-for="item in tableList" :value="item.fullname">{{ item.fullname }}</Option>
                  </Select>
                </FormItem>
              </Col>
              <Col span="12">
                <FormItem label="生成路径" required class="my-form-item">
                  <Dropdown placement="bottom-start" @on-click="handleDropdownClick" style="width:100%;">
                      <a href="javascript:void(0)">
                        <Input v-model="path" placeholder="请输入生成路径" /> 
                      </a>
                      <DropdownMenu slot="list">
                          <DropdownItem  v-for="item in moduleList" :name="item">{{ item }}</DropdownItem>
                      </DropdownMenu>
                  </Dropdown>
                </FormItem>
              </Col>
            </Row>
            <Row :gutter="32">
              <Col span="12">
                <FormItem label="文件名称" required class="my-form-item">
                  <Input v-model="filename" placeholder="请输入文件名称" /> 
                </FormItem>
              </Col>
              <Col span="12">
                <FormItem label="组件名称" required class="my-form-item">
                  <Input v-model="componentname" placeholder="请输入组件名称" /> 
                </FormItem>
              </Col>
            </Row>
            <Row :gutter="32">
              <Col span="12">
                <FormItem label="列表接口" required class="my-form-item">
                  <Input v-model="api.listApi" placeholder="请输入列表接口" /> 
                </FormItem>
              </Col>
              <Col span="12">
                <FormItem label="添加接口" required class="my-form-item">
                  <Input v-model="api.createApi" placeholder="请输入添加接口" /> 
                </FormItem>
              </Col>
            </Row>
            <Row :gutter="32">
              <Col span="12">
                <FormItem label="编辑接口" required class="my-form-item">
                  <Input v-model="api.editApi" placeholder="请输入编辑接口" /> 
                </FormItem>
              </Col>
              <Col span="12">
                <FormItem label="删除接口" required class="my-form-item">
                  <Input v-model="api.deleteApi" placeholder="请输入删除接口" /> 
                </FormItem>
              </Col>
            </Row>
            <Row :gutter="32">
              <Col span="12">
                <FormItem label="主键" required class="my-form-item">
                  <Input v-model="pk" placeholder="请输入主键依据" /> 
                </FormItem>
              </Col>
            </Row>
          </Form>
        </Card>
      </i-col>
      <i-col span="12">
        <Card class="my-card">
          <p slot="title">
              <Icon type="md-reorder"></Icon>
              菜单配置
          </p>
          <Spin size="large" fix v-show="spinShow"></Spin>
          <Form  :label-width="80" ref="mform" v-show="formShow" inline>
            <Row :gutter="32">
                <Col span="24">
                    <FormItem label="菜单名称" label-position="top" required class="my-form-item">
                        <Input v-model="menu.title" placeholder="请输入菜单名称" />
                    </FormItem>
                </Col>
            </Row>
            <Row :gutter="32">
                <Col span="12">
                    <FormItem label="路由名称" label-position="top" class="my-form-item" required>
                        <Input v-model="menu.name" placeholder="请输入路由名称" />
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="路由" label-position="top" class="my-form-item" required>
                        <Input v-model="menu.path" placeholder="请输入路由" />
                    </FormItem>
                </Col>
            </Row>
            <Row :gutter="32">
              <Col span="24">
                    <FormItem label="组件地址" label-position="top" class="my-form-item" >
                        <Input v-model="menu.component" placeholder="请输入组件文件所在路径" />
                    </FormItem>
              </Col>
              
            </Row>
            <Row :gutter="32">
              <Col span="12">
                    <FormItem label="父菜单" label-position="top" class="my-form-item" required>
                        <Select v-model="menu.parent_id" placeholder="请选择父级">
                          <Option :value="0" label="顶级菜单"><span style="fontWeight:600;">顶级菜单</span></Option>
                          <template v-for="item in menuData">
                            <Option :value="item.menu_id" :label="item.title" v-if="item.type == 0"><span style="fontWeight:600;">{{ item.title }}</span></Option>
                            <template v-for="sec in item.children">
                              <Option  :value="sec.menu_id" :label="sec.title" v-if="sec.type == 0"><span style="paddingLeft:10px;">{{ sec.title }}</span></Option>
                                <Option v-for="thr in sec.children" v-if="thr.type == 0"  :value="thr.menu_id" :label="thr.title"><span style="paddingLeft:20px;">{{ thr.title }}</span></Option>
                            </template>
                          </template>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="LOGO" label-position="top" class="my-form-item" required>
                        <Input v-model="menu.icon" placeholder="请输入LOGO" >
                          <Icon :type="menu.icon" slot="prefix" />
                        </Input>
                    </FormItem>
                </Col>
            </Row>
            <Row :gutter="32">
              <Col span="12">
                    <FormItem label="排序" label-position="top" class="my-form-item">
                        <InputNumber :min="0" v-model="menu.sort" style="width:100%;"></InputNumber>
                    </FormItem>
              </Col>
            </Row>
            
          </Form>
        </Card>
      </i-col>
    </Row>
    <Row>
      <i-col span="24">
        <Card class="my-card">
          <p slot="title">
            <Icon type="ios-cog" />
              操作
          </p>
          <Button type="primary" slot="extra" @click="createMC">生成</Button>
          <Spin size="large" fix v-show="tableShow"></Spin>
          <Table :columns="columns" :data="data"></Table>
        </Card>
      </i-col>
    </Row>
    <Row>
      <i-col span="24">
        <Card class="my-card">
          <p slot="title">
            <Icon type="md-color-wand" />
              表头搜索前置按钮
          </p>
          <Spin size="large" fix v-show="tableShow"></Spin>
          <Form v-show="selectTableStatus">
              <FormItem
                      v-for="(item, index) in formButtonBeforeSearch"
                      :key="index">
                  <Row :gutter="4">
                      <Col span="3">
                          <Button :type="item.type || 'default'"  :icon="item.logo">{{ item.title }}</Button>
                      </Col>
                      <Col span="4">
                          <Input type="text" v-model="item.title" placeholder="按钮名称" ></Input>
                      </Col>
                      <Col span="4">
                          <Input type="text" v-model="item.name" placeholder="按钮标识" ></Input>
                      </Col>
                      <Col span="3">
                          <Select v-model="item.type" placeholder="按钮样式" >
                              <Option v-for="button in buttonSelectList" :value="button" :label="button" :key="`bsb_` + button">
                                  <span><Button :type="button" size="small">{{ button }}</Button></span>
                              </Option>
                          </Select>
                      </Col>
                      <Col span="4">
                          <Input v-model="item.logo" placeholder="请输入LOGO" >
                            <Icon :type="item.logo" slot="prefix" />
                          </Input>
                      </Col>
                      <Col span="3" style="textAlign:center;">
                          <Checkbox v-model="item.confirm">是否提示</Checkbox>
                      </Col>
                      <Col span="2">
                          <Poptip
                          confirm
                          title="你确定要删除吗?"
                          @on-ok="handleButtonRemove(item.index, 'BeforeSearch')"
                          >
                              <Button type="warning">删除</Button>
                          </Poptip>
                      </Col>
                  </Row>
              </FormItem>
              <FormItem>
                  <Row>
                      <Col span="6">
                          <Button type="dashed" long @click="handleButtonAdd('BeforeSearch')" icon="md-add">添加</Button>
                      </Col>
                  </Row>
              </FormItem>
          </Form>
        </Card>
      </i-col>
    </Row>
    <Row>
      <i-col span="24">
        <Card class="my-card">
          <p slot="title">
            <Icon type="md-color-wand" />
              表头搜索后置按钮
          </p>
          <Spin size="large" fix v-show="tableShow"></Spin>
          <Form v-show="selectTableStatus">
              <FormItem
                      v-for="(item, index) in formButtonAfterSearch"
                      :key="index">
                  <Row :gutter="4">
                      <Col span="3">
                          <Button :type="item.type || 'default'"  :icon="item.logo">{{ item.title }}</Button>
                      </Col>
                      
                      <Col span="4">
                          <Input type="text" v-model="item.title" placeholder="按钮名称" ></Input>
                      </Col>
                      <Col span="4">
                          <Input type="text" v-model="item.name" placeholder="按钮标识" ></Input>
                      </Col>
                      <Col span="3">
                          <Select v-model="item.type" placeholder="按钮样式" >
                              <Option v-for="button in buttonSelectList" :value="button" :label="button" :key="`bab_` + button">
                                  <span><Button :type="button" size="small">{{ button }}</Button></span>
                              </Option>
                          </Select>
                      </Col>
                      <Col span="4">
                          <Input v-model="item.logo" placeholder="请输入LOGO" >
                            <Icon :type="item.logo" slot="prefix" />
                          </Input>
                      </Col>
                      <Col span="3" style="textAlign:center;">
                          <Checkbox v-model="item.confirm">是否提示</Checkbox>
                      </Col>
                      <Col span="2">
                          <Poptip
                          confirm
                          title="你确定要删除吗?"
                          @on-ok="handleButtonRemove(item.index, 'AfterSearch')"
                          >
                              <Button type="warning">删除</Button>
                          </Poptip>
                      </Col>
                  </Row>
              </FormItem>
              <FormItem>
                  <Row>
                      <Col span="6">
                          <Button type="dashed" long @click="handleButtonAdd('AfterSearch')" icon="md-add">添加</Button>
                      </Col>
                  </Row>
              </FormItem>
          </Form>
        </Card>
      </i-col>
    </Row>
    <Row>
      <i-col span="24">
        <Card class="my-card">
          <p slot="title">
            <Icon type="md-color-wand" />
              行按钮
          </p>
          <Spin size="large" fix v-show="tableShow"></Spin>
          <Form v-show="selectTableStatus">
              <FormItem
                      v-for="(item, index) in formButtonRow"
                      :key="index">
                  <Row :gutter="4">
                      <Col span="3">
                          <Button :type="item.type || 'default'"  :icon="item.logo">{{ item.title }}</Button>
                      </Col>
                      <Col span="4">
                          <Input type="text" v-model="item.title" placeholder="按钮名称" ></Input>
                      </Col>
                      <Col span="4">
                          <Input type="text" v-model="item.name" placeholder="按钮标识" ></Input>
                      </Col>
                      <Col span="3">
                          <Select v-model="item.type" placeholder="按钮样式" >
                              <Option v-for="button in buttonSelectList" :value="button" :label="button" :key="`brb_` + button">
                                  <span><Button :type="button" size="small">{{ button }}</Button></span>
                              </Option>
                          </Select>
                      </Col>
                      <Col span="4">
                          <Input v-model="item.logo" placeholder="请输入LOGO" >
                            <Icon :type="item.logo" slot="prefix" />
                          </Input>
                      </Col>
                      <Col span="3" style="textAlign:center;">
                          <Checkbox v-model="item.confirm">是否提示</Checkbox>
                      </Col>
                      <Col span="2">
                          <Poptip
                          confirm
                          title="你确定要删除吗?"
                          @on-ok="handleButtonRemove(item.index, 'Row')"
                          >
                              <Button type="warning">删除</Button>
                          </Poptip>
                      </Col>
                  </Row>
              </FormItem>
              <FormItem>
                  <Row>
                      <Col span="6">
                          <Button type="dashed" long @click="handleButtonAdd('Row')" icon="md-add">添加</Button>
                      </Col>
                  </Row>
              </FormItem>
          </Form>
        </Card>
      </i-col>
    </Row>
  </div> 
</template>

<script>
import { oneOf } from '@/libs/tools'
import { getTableList, codeCreateMC, getTableField, codeCreateVue, codeVerifyPath, getMenuData } from '@/api/codebase'

export default {
  name: 'vcode_pages',
  data () {
    return {
      columns: [
        {
          title: '字段',
          key: 'field'
        },
        {
          title: '注释',
          key: 'com',
          render: (h, params) => {
            return (
              <Input placeholder={params.row.com} v-model={this.fieldsAlias[params.row.field]}/>
            )
          }
        },
        {
          title: '类型',
          key: 'field',
          render: (h, params) => {
            return (
              <Cascader data={this.typeSelect} v-model={this.fieldsType[params.row.field]} ></Cascader>
            )
          }
        },
        {
          title: '配置',
          key: 'field',
          render: (h, params) => {
            let textAreaSize = {minRows: 5,maxRows: 8}
            return (
              <Poptip placement="right" width="400" title="选项">
                  <Button type="success" size="small" v-show={this.hasConfigOption(this.fieldsType[params.row.field][0])}>选项</Button>
                  <div class="api" slot="content">
                      <Tabs value={'dataApi' + params.row.field} v-show={this.hasConfigOptionNotUp(this.fieldsType[params.row.field][0])}>
                          <TabPane label="数据接口" name={'dataApi' + params.row.field} >
                              <Form label-width={55} label-position="left">
                                  <FormItem label="数据接口">
                                      <Input placeholder="请输入数据源接口" v-model={this.fieldsConf[params.row.field].dataApi}></Input>
                                  </FormItem>
                                  <FormItem label="ValueKey">
                                      <Input placeholder="请输入Value键" v-model={this.fieldsConf[params.row.field].valueKey}></Input>
                                  </FormItem>
                                  <FormItem label="NameKey">
                                      <Input placeholder="请输入Name键" v-model={this.fieldsConf[params.row.field].nameKey}></Input>
                                  </FormItem>
                              </Form>
                          </TabPane>
                          <TabPane label="自定义" name={'datasefdef' + params.row.field}>
                              <Input type="textarea" v-model={this.fieldsConf[params.row.field].selfDef} autosize={textAreaSize} placeholder="value#title，请换行"></Input>
                          </TabPane>
                      </Tabs>
                      <Form label-width={55} label-position="left" style="marginTop:10px;" v-show={this.fieldsType[params.row.field][0] == 'upload'}>
                          <FormItem label="上传地址">
                              <Input placeholder="请输入上传地址" v-model={this.fieldsConf[params.row.field].uploadApi}></Input>
                          </FormItem>
                          <FormItem label="保存路径">
                              <Input placeholder="请输入保存路径，统一放在public/uploads/下" v-model={this.fieldsConf[params.row.field].uploadPath}></Input>
                          </FormItem>
                          <FormItem label="上传格式">
                              <Input placeholder="请输入上传格式，如'jpg,png,...'" v-model={this.fieldsConf[params.row.field].uploadFormat}></Input>
                          </FormItem>
                      </Form>
                  </div>
              </Poptip>
            )
          }
        },
        {
          title: '列表',
          key: 'field',
          render: (h, params) => {
            return (
              <Checkbox v-model={this.listfields[params.row.field]}></Checkbox>
            )
          },
          renderHeader: (h, params) => {
            let type = 'listfields'
            return (
              <Checkbox v-model={this.listfieldsStatusAll} nativeOn-click={e => this.changeCheckStatusAll(type, e)}>列表</Checkbox>
            )
          }
        },
        {
          title: '搜索',
          key: 'field',
          render: (h, params) => {
            return (
              <Checkbox v-model={this.searchfields[params.row.field]}></Checkbox>
            )
          },
          renderHeader: (h, params) => {
            let type = 'searchfields'
            return (
              <Checkbox v-model={this.searchfieldsStatusAll} nativeOn-click={e => this.changeCheckStatusAll(type, e)}>搜索</Checkbox>
            )
          }
        },
        {
          title: '添加编辑',
          key: 'field',
          render: (h, params) => {
            return (
              <Checkbox v-model={this.editfields[params.row.field]}></Checkbox>
            )
          },
          renderHeader: (h, params) => {
            let type = 'editfields'
            return (
              <Checkbox v-model={this.editfieldsStatusAll} nativeOn-click={e => this.changeCheckStatusAll(type, e)}>添加编辑</Checkbox>
            )
          }
        }
      ],
      data: [],
      table: '',
      path: '',
      filename: 'index',
      componentname: '',
      listfields: {},
      searchfields: {},
      editfields: {},
      fieldsAlias: {},
      fieldsType: {},
      fieldsConf: {},
      listfieldsStatusAll: false,
      searchfieldsStatusAll: false,
      editfieldsStatusAll: false,
      typeSelect: [
        {
          value: 'input',
          label: '输入框'
        },
        {
          value: 'select',
          label: '选择器'
        },
        {
          value: 'radio',
          label: '单选框'
        },
        {
          value: 'checkbox',
          label: '复选框'
        },
        {
          value: 'datepicker',
          label: '日期选择器',
          children: [
            {
              value: 'date',
              label: '日期'
            },
            {
              value: 'daterange',
              label: '日期范围'
            },
            {
              value: 'datetime',
              label: '日期时间'
            },
            {
              value: 'datetimerange',
              label: '日期时间范围'
            },
            {
              value: 'year',
              label: '年份'
            },
            {
              value: 'month',
              label: '月份'
            }
          ]
        },
        {
          value: 'timepicker',
          label: '时间选择器',
          children: [
            {
              value: 'time',
              label: '时间'
            },
            {
              value: 'timerange',
              label: '时间范围'
            }
          ]
        },
        {
          value: 'textarea',
          label: '文本',
          children: [
            {
              value: 'textarea',
              label: '文本框'
            },
            {
              value: 'editor',
              label: '富文本'
            }
          ]
        },
        {
          value: 'upload',
          label: '上传',
          children: [
            {
              value: 'single',
              label: '单文件'
            },
            {
              value: 'multiple',
              label: '多文件'
            }
          ]
        }
      ],
      tableList: [],
      moduleList: [],
      prefix: '',
      spinShow: true,
      formShow: false,
      tableShow: false,
      api: {
        listApi : 'listApi',
        editApi : 'editApi',
        createApi : 'createApi',
        deleteApi : 'deleteApi'
      },
      pk: 'id',
      menu: {
        title: '',
        name: '',
        path: '',
        component: '',
        icon: '',
        sort: 0,
        parent_id: 0
      },
      menuData: [],
      selectTableStatus: false,
      buttonIndex: 4,
      formButtonBeforeSearch: [],
      formButtonAfterSearch: [],
      formButtonRow: [],
      buttonSelectList:['default', 'dashed', 'info', 'primary', 'success', 'warning', 'error']
    }
  },
  watch: {
    path: function(newPath){
      this.menu.component = 'view/' + newPath + '/' + this.filename
    },
    filename: function(newName){
      this.menu.component = 'view/' + this.path + '/' + newName
    }
  },
  methods: {
    changeCheckStatusAll(type, e){
      // e.stopPropagation()
      console.log(this[type])
      for(let k in this[type]){
        this[type][k] = !this[type + 'StatusAll']
      }
    },
    hasConfigOption (type) {
      let arr = ['select', 'radio', 'checkbox', 'upload']
      return oneOf(type, arr)
    },
    hasConfigOptionNotUp (type) {
      let arr = ['select', 'radio', 'checkbox']
      return oneOf(type, arr)
    },
    handleDropdownClick (name) {
      this.path = name
    },
    handleTableSelect (value) {
      this.tableShow = true
      let table = value.replace(this.prefix, '')
      this.menu.name = table
      this.menu.path = table
      this.listfieldsStatusAll = false
      this.searchfieldsStatusAll = false
      this.editfieldsStatusAll = false
      this.reloadformbuttons(table)

      getTableField(value).then(res => {
        
        this.listfields = {}
        this.searchfields = {}
        this.editfields = {}
        this.fieldsAlias = {}
        this.fieldsType = {}
        this.fieldsConf = {}
        this.componentname = value + '_pages'
        this.api.listApi = this.transformStr('get_' + table + 'Data')
        this.api.createApi = this.transformStr('create_' + table)
        this.api.editApi = this.transformStr('update_' + table)
        this.api.deleteApi = this.transformStr('delete_' + table)

        res.data.data.forEach(item => {
          let it_field = {}, it_com = {}, obj = {}, it_conf = {}

          it_field[item.field] = false
          this.listfields = Object.assign({}, this.listfields, it_field)
          this.searchfields = Object.assign({}, this.searchfields, it_field)
          this.editfields = Object.assign({}, this.editfields, it_field)

          it_com[item.field] = item.com
          this.fieldsAlias = Object.assign({}, this.fieldsAlias, it_com)
          // this.listfields[item.field] = false
          // this.searchfields[item.field] = false
          // this.editfields[item.field] = false
          // this.fieldsAlias[item.field] = item.com
          obj[item.field] = ["init"]
          this.fieldsType = Object.assign({}, this.fieldsType, obj)

          it_conf[item.field] = {
            dataApi: '',
            valueKey: 'id',
            nameKey: 'title',
            selfDef: '',
            uploadApi: '',
            uploadPath: '',
            uploadFormat: ''
          }
          this.fieldsConf = Object.assign({}, this.fieldsConf, it_conf)

          if(item.key == 'PRI'){
            this.pk = item.field
          }
        })
        this.data = res.data.data
        this.selectTableStatus = true
        this.tableShow = false
      })
    },
    reloadformbuttons (table) {
      this.formButtonBeforeSearch = [
        {
          title: '添加',
          name: 'add',
          type: 'primary',
          logo: 'md-add',
          confirm: false,
          permission: table + '_button_add',
          index: 1,
          status: true
        }
      ]
      this.formButtonAfterSearch = [
        {
          title: '导出',
          name: 'export',
          type: 'success',
          logo: 'md-archive',
          confirm: false,
          permission: table + '_button_export',
          index: 2,
          status: true
        }
      ]
      this.formButtonRow = [
        {
          title: '编辑',
          type: 'success',
          name: 'edit',
          logo: 'md-create',
          confirm: false,
          permission: table + '_button_edit',
          index: 3,
          status: true
        },
        {
          title: '删除',
          name: 'delete',
          type: 'error',
          logo: 'md-trash',
          confirm: true,
          permission: table + '_button_delete',
          index: 4,
          status: true
        }
      ]
      this.buttonIndex = 4
    },
    transformStr (str) {
        var newStr = '';
        var arr = str.split('_');
        for(var i = 0; i<arr.length; i++){
            var s = arr[i];
            if(i == 0){
                newStr += s;
            }else{
                newStr += s.substr(0, 1).toLocaleUpperCase();
                newStr += s.substr(1, s.length-1);
            }
        }
        return newStr;
    },
    createMC () {
      if(this.table == ''){
        this.$Message.error('请选择一项数据表');
        return
      }
      if(this.path == ''){
        this.$Message.error('请选择保存路径');
        return
      }
      if(this.filename == ''){
        this.$Message.error('请填写文件名称');
        return
      }
      if(this.menu.title == ''){
        this.$Message.error('请填写菜单名称');
        return
      }
      if(this.menu.name == ''){
        this.$Message.error('请填写路由名称');
        return
      }
      if(this.menu.path == ''){
        this.$Message.error('请填写路由地址');
        return
      }
      if(this.menu.icon == ''){
        this.$Message.error('请填写菜单LOGO');
        return
      }
  
      let listfields = this.objPropFilter(this.listfields);
      let searchfields = this.objPropFilter(this.searchfields);
      let editfields = this.objPropFilter(this.editfields);
      
      // let formButtonBeforeSearch = this.formButtonBeforeSearch
      // let formButtonAfterSearch = this.formButtonAfterSearch
      // let formButtonRow = this.formButtonRow
      // let pre_table = this.table
      // let table = pre_table.replace(this.prefix, '')

      // formButtonBeforeSearch.forEach(item => {
      //   item.permission = table + '_' + this.filename + '_button_index' + item.index
      // })
      // formButtonAfterSearch.forEach(item => {
      //   item.permission = table + '_' + this.filename + '_button_index' + item.index
      // })
      // formButtonRow.forEach(item => {
      //   item.permission = table + '_' + this.filename + '_button_index' + item.index
      // })
      let _this = this

      codeVerifyPath({
        table: this.table,
        path: this.path,
        file: this.filename,
        component: this.componentname,
        list: listfields,
        search: searchfields,
        edit: editfields,
        alias: this.fieldsAlias,
        types: this.fieldsType,
        conf: this.fieldsConf,
        api: this.api,
        pk: this.pk,
        menu: this.menu,
        buttons: {
          'beforeSearch': _this.formButtonBeforeSearch,
          'afterSearch': _this.formButtonAfterSearch,
          'row': _this.formButtonRow
        }
      }).then(res => {
        if(res.data.code == 500){
          this.$Modal.confirm({
              title: '警告',
              content: res.data.msg,
              okText: '覆盖',
              cancelText: '取消',
              onOk: () => {
                  codeCreateVue().then(res => {
                    this.$Notice.info({
                      title: '通知',
                      duration: 15,
                      render: h => {
                          return h('span', {
                            domProps: {
                              innerHTML: res.data.msg
                            }
                          })
                      }
                    });
                  })
              }
          })
        }else{
          this.$Notice.info({
            title: '通知',
            duration: 15,
            render: h => {
                return h('span', {
                  domProps: {
                    innerHTML: res.data.msg
                  }
                })
            }
          });
        }
      })
    },
    objPropFilter (obj) {
      let arr = [];
      for(let k in obj){
        if(obj[k]){
          arr.push(k)
        }
      }
      return arr
    },
    handleButtonAdd (type) {
      let pre_table = this.table
      let table = pre_table.replace(this.prefix, '')
      let filename = this.filename
      this.buttonIndex++;
      this['formButton' + type].push({
          title: 'default',
          type: '',
          logo: '',
          confirm: false,
          permission: table + '_button_index' + this.buttonIndex,
          index: this.buttonIndex,
          status: false
      })
    },
    handleButtonRemove (buttonIndex, type) {
      this['formButton' + type] = this['formButton' + type].filter((item, index) => item.index !== buttonIndex)
    }
  },
  mounted () {
    getTableList({ path: 'view' }).then(res => {
      if(res.data.code == 200){
        this.spinShow = false
        this.formShow = true
        this.tableList = res.data.data.tables
        this.moduleList = res.data.data.modules
        this.prefix = res.data.data.prefix
      }
    })
    getMenuData().then(res => {
      console.log(res)
      this.menuData = res.data.data
    })
  }
}
</script>

<style scoped>
.my-card{
  margin: 0 5px 5px;
}
.my-form-item{
  width:100%;
  margin-top: 10px;
}
.my-row{
  margin-bottom: 10px;
}
</style>
